export default {
  // 获取数据
  get(key: string) {
    const _value = localStorage.getItem(key);
    if (!_value) {
      return null;
    }
    return JSON.parse(_value);
  },
  // 设置数据
  set(key: string, value: any) {
    if (value === undefined || value === null) {
      localStorage.setItem(key, '');
      return;
    }
    localStorage.setItem(key, JSON.stringify(value));
  },
  // sessionStorage
  sessionGet(key: string) {
    const _value = sessionStorage.getItem(key);
    if (!_value) {
      return null;
    }
    return JSON.parse(_value);
  },
  sessionSet(key: string, value: any) {
    if (value === undefined || value === null) {
      sessionStorage.setItem(key, '');
      return;
    }
    sessionStorage.setItem(key, JSON.stringify(value));
  },
};
